<template>
  <div>
    <el-card :bordered="false" shadow="never" class="ivu-mt" :body-style="{ padding: 0 }">
      <div class="padding-add">
        <el-form
          ref="userFrom"
          :model="userFrom"
          label-width="80px"
          label-position="right"
          @submit.native.prevent
          inline
        >
          <div class="acea-row search-form" v-if="!collapse">
            <div>
              
			  
			  
              <el-form-item label="所属科目：" label-for="level" v-if="userFrom.user_type == '2'">
                <el-select v-model="userFrom.belong_subject" placeholder="请选择所属科目" clearable class="form_content_width">
                  <el-option value="all" label="全部">全部</el-option>
                  <el-option
                    :value="item.id"
                    v-for="(item, index) in levelList"
                    :key="index"
                    :label="item.cate_name"
                  ></el-option>
                </el-select>
              </el-form-item>
			  
			  <el-form-item label="代理商是否享受活动：" v-if="userFrom.user_type == '4'">
			    <el-select v-model="userFrom.is_activity" placeholder="请选择" clearable class="form_content_width">
			      <el-option value="" label="全部"></el-option>
			      <el-option value="1" label="享受"></el-option>
			      <el-option value="2" label="不享受"></el-option>
			    </el-select>
			  </el-form-item>
			  
			  <el-form-item label="分组：" v-if="userFrom.user_type == '4'">
			    <el-select v-model="userFrom.agent_grouping_id" placeholder="请选择" clearable class="form_content_width">
			      <el-option value="" label="全部"></el-option>
			      
			      <el-option v-for="item in groupinglist" :value="item.id" :label="item.name"></el-option>
			    </el-select>
			  </el-form-item>
			  
			  <el-form-item label="账号状态：">
			    <el-select v-model="userFrom.status" placeholder="请选择" clearable class="form_content_width">
			      <el-option value="" label="全部"></el-option>
			      <el-option value="1" label="正常"></el-option>
			      <el-option value="0" label="禁用"></el-option>
			    </el-select>
			  </el-form-item>
			  
			  <el-form-item label="学生年级：">
			    <el-select v-model="userFrom.class" placeholder="请选择" clearable class="form_content_width">
			      <el-option value="" label="全部"></el-option>
			      <el-option value="1" label="初一"></el-option>
			      <el-option value="2" label="初二"></el-option>
				  <el-option value="3" label="初三"></el-option>
				  <el-option value="7" label="初四"></el-option>
				  <el-option value="4" label="高一"></el-option>
				  <el-option value="5" label="高二"></el-option>
				  <el-option value="6" label="高三"></el-option>
			    </el-select>
			  </el-form-item>
			  
              <el-form-item label="用户搜索：" label-for="nickname">
                <el-input v-model="userFrom.nickname" placeholder="请输入用户" clearable class="form_content_width">
                  <el-select v-model="field_key" slot="prepend" style="width: 100px">
                    <el-option value="all" label="全部"></el-option>
                    <el-option value="uid" label="UID"></el-option>
                    <el-option value="phone" label="手机号"></el-option>
                    <el-option value="real_name" label="用户姓名"></el-option>
					<el-option value="account" label="用户账号"></el-option>
					<el-option value="mask_nickname" label="代理商昵称"></el-option>
                  </el-select>
                </el-input>
              </el-form-item>
            </div>
            <el-form-item class="search-form-sub">
              <el-button type="primary" v-db-click @click="userSearchs">搜索</el-button>
              <el-button class="ResetSearch" v-db-click @click="reset('userFrom')">重置</el-button>
              <!-- <a class="ivu-ml-8 font12 ml10" v-db-click @click="collapse = !collapse">
                <template v-if="!collapse"> 展开 <i class="el-icon-arrow-down" /> </template>
                <template v-else> 收起 <i class="el-icon-arrow-up" /> </template>
              </a> -->
            </el-form-item>
          </div>
          <div v-if="collapse" class="acea-row search-form">
            <div class="search-form-box">
         
            </div>

            <el-form-item class="search-form-sub">
              <el-button type="primary" label="default" v-db-click @click="userSearchs">搜索</el-button>
              <el-button class="ResetSearch" v-db-click @click="reset('userFrom')">重置</el-button>
              <a class="ivu-ml-8 font12 ml10" v-db-click @click="collapse = !collapse">
                <template v-if="!collapse"> 展开 <i class="el-icon-arrow-down" /> </template>
                <template v-else> 收起 <i class="el-icon-arrow-up" /> </template>
              </a>
            </el-form-item>
          </div>
        </el-form>
      </div>
    </el-card>
    <el-card :bordered="false" shadow="never" class="ivu-mt mt16" :body-style="{ padding: '0 20px 20px' }">
      <el-tabs v-model="userFrom.user_type" @tab-click="onClickTab">
        <el-tab-pane :label="item.name" :name="item.type" v-for="(item, index) in headeNum" :key="index" />
      </el-tabs>
      <el-row :gutter="24" justify="space-between">
        <el-col :span="24">
          <!-- <el-button v-auth="['admin-user-save']" type="primary" v-db-click @click="edit({ uid: 0 })">添加用户</el-button> -->
          <el-button  type="primary" v-if="roles == 777 || roles == 1 || roles == 10"  @click="edit({ uid: 0 })">添加用户</el-button>
          <!-- <el-button v-auth="['admin-user-coupon']" v-db-click @click="onSend">发送优惠券</el-button> -->
          <el-button
            v-auth="['admin-wechat-news']"
            class="greens mr10"
            v-db-click @click="onSendPic"
            v-if="userFrom.user_type === 'wechat'"
          >
            发送图文消息
          </el-button>
          <!-- <el-button v-auth="['admin-user-group_set']" v-db-click @click="setGroup">批量设置分组</el-button>
          <el-button v-auth="['admin-user-set_label']" v-db-click @click="setLabel">批量设置标签</el-button> -->
		  
		 
			  <el-button v-if="roles == 777" v-db-click @click="batch_disable">账号禁用</el-button>
			  <el-button v-if="roles == 777" v-db-click @click="batch_disable_all" style="background-color: red;color: #fff;">全部禁用</el-button>
			  
			  
			  <el-button v-if="roles == 777 && userFrom.user_type == '1'" v-db-click @click="course_batch_disable">学员课程禁用</el-button>
			  <el-button v-if="roles == 777 && userFrom.user_type == '1'" v-db-click @click="all_course_batch_disable">所有学员课程禁用</el-button>
			  
		  
		  
          <!-- <el-button class="mr10" v-db-click @click="exportList">导出</el-button> -->
          <!-- <el-button v-auth="['admin-user-synchro']" class="mr20" v-db-click @click="synchro">同步公众号用户</el-button> -->
        </el-col>
        <el-col :span="24" class="userAlert" v-if="selectionList.length">
          <el-alert show-icon>
            <template slot="title">
              已选择<i class="userI"> {{ selectionList.length }} </i>项
            </template>
          </el-alert>
        </el-col>
      </el-row>
      <el-table
        :data="userLists"
        class="mt16"
        ref="table"
        highlight-current-row
        v-loading="loading"
        empty-text="暂无数据"
        no-filtered-userFrom-text="暂无筛选结果"
        @sort-change="sortChanged"
        @select="handleSelectRow"
        @select-all="handleSelectAll"
      >
        <el-table-column type="expand">
          <template slot-scope="scope">
            <expandRow :row="scope.row"></expandRow>
          </template>
        </el-table-column>
        <el-table-column type="selection" :selectable="isSel" width="55"> </el-table-column>
        <el-table-column label="用户ID" min-width="50">
          <template slot-scope="scope">
            <span>{{ scope.row.uid }}</span>
          </template>
        </el-table-column>
       
        <el-table-column label="姓名" min-width="110">
          <template slot-scope="scope">
			<div>{{ scope.row.real_name }}</div>
          </template>
        </el-table-column>
		
		<el-table-column label="昵称" min-width="130" v-if="userFrom.user_type == 4">
		  <template slot-scope="scope">
			<div>{{ scope.row.mask_nickname }}</div>
		  </template>
		</el-table-column>
		
		<el-table-column label="登录账号" min-width="120">
		  <template slot-scope="scope">
			<div>{{ scope.row.account }}</div>
		  </template>
		</el-table-column>
		<!-- <el-table-column label="手机号" min-width="150">
		  <template slot-scope="scope">
			<div>{{ scope.row.phone }}</div>
		  </template>
		</el-table-column> -->
		<!-- <el-table-column label="用户类型" min-width="80">
		  <template slot-scope="scope">
			<div>{{ scope.row.customer_type_name }}</div>
		  </template>
		</el-table-column> -->
		
		<el-table-column label="所属年级" v-if="userFrom.user_type == 1" min-width="70">
		  <template slot-scope="scope">
			<div>{{ scope.row.class_name }}</div>
		  </template>
		</el-table-column>
		
		<el-table-column label="毕业年限" v-if="userFrom.user_type == 1" min-width="80">
		  <template slot-scope="scope">
			<div>{{ scope.row.graduate_text || '无' }}</div>
		  </template>
		</el-table-column>
		
		<el-table-column v-if="userFrom.user_type == 1" label="性别" min-width="80">
		  <template slot-scope="scope">
			<div v-if="scope.row.gender == 1">男生</div>
			<div v-if="scope.row.gender == 2">女生</div>
		  </template>
		</el-table-column>
		
		<el-table-column v-if="userFrom.user_type == 1" label="所属代理" min-width="150">
		  <template slot-scope="scope">
			<div>{{ scope.row.belong_agent_name }}</div>
		  </template>
		</el-table-column>
		
		
		
	<!-- 	
		<el-table-column v-if="userFrom.user_type == 1" label="学员类型" min-width="150">
		  <template slot-scope="scope">
			<div v-if="scope.row.user_identity == 1">普通学员</div>
			<div v-else >付费学员</div>
		  </template>
		</el-table-column> -->
		
		<el-table-column v-if="userFrom.user_type == 4" label="代理商类型" min-width="100">
		  <template slot-scope="scope">
			<div >{{scope.row.agent_type_name}}</div>
		  </template>
		</el-table-column>
		
		<el-table-column v-if="userFrom.user_type == 4" label="是否享受活动" min-width="100">
		  <template slot-scope="scope">
			<div v-if="scope.row.is_activity == 1">享受</div>
			<div v-if="scope.row.is_activity == 2">不享受</div>
		  </template>
		</el-table-column>
		
		<el-table-column  v-if="userFrom.user_type == 4" label="所属分组" min-width="90">
		  <template slot-scope="scope">
			<div >{{scope.row.agent_grouping_name}}</div>
		  </template>
		</el-table-column>
		
		<el-table-column label="账号状态" min-width="70">
		  <template slot-scope="scope">
			<div >{{scope.row.status}}</div>
		  </template>
		</el-table-column>
		<el-table-column label="添加时间" min-width="150">
		  <template slot-scope="scope">
			<div>{{ scope.row.add_time }}</div>
		  </template>
		</el-table-column>
        <!-- <el-table-column label="付费会员" min-width="90">
          <template slot-scope="scope">
            <div>{{ scope.row.isMember ? '是' : '否' }}</div>
          </template>
        </el-table-column>
        <el-table-column label="用户等级" min-width="90">
          <template slot-scope="scope">
            <div>{{ scope.row.level }}</div>
          </template>
        </el-table-column>
        <el-table-column label="分组" min-width="100">
          <template slot-scope="scope">
            <div>{{ scope.row.group_id }}</div>
          </template>
        </el-table-column>
        <el-table-column label="手机号" min-width="100">
          <template slot-scope="scope">
            <div>{{ scope.row.phone }}</div>
          </template>
        </el-table-column> -->
        <!-- <el-table-column label="用户类型" min-width="100">
          <template slot-scope="scope">
            <div>{{ scope.row.user_type }}</div>
          </template>
        </el-table-column> -->
        <!-- <el-table-column label="余额" prop="now_money" min-width="100" :sortable="true">
          <template slot-scope="scope">
            <div>{{ scope.row.now_money }}</div>
          </template>
        </el-table-column> -->
        <el-table-column label="操作" fixed="right" width="120">
          <template slot-scope="scope">
            <template v-if="scope.row.is_del != 1">
              <a v-db-click @click="userDetail(scope.row)">详情</a>

              <el-divider direction="vertical"></el-divider>
              <el-dropdown size="small" @command="changeMenu(scope.row, $event, scope.$index)" :transfer="true">
                <span class="el-dropdown-link">更多<i class="el-icon-arrow-down el-icon--right"></i> </span>
                <el-dropdown-menu slot="dropdown">
                  <!-- <el-dropdown-item command="1">编辑</el-dropdown-item> -->
                  <!-- <el-dropdown-item command="2">积分余额</el-dropdown-item> -->
                  <!-- <el-dropdown-item command="3">赠送会员</el-dropdown-item> -->
                  <!--                                <el-dropdown-item command="4" v-if="row.vip_name">清除等级</el-dropdown-item>-->
                  <!-- <el-dropdown-item command="5">设置分组</el-dropdown-item> -->
                  <!-- <el-dropdown-item command="6">设置标签</el-dropdown-item> -->
                  <!-- <el-dropdown-item command="7">修改上级推广人</el-dropdown-item> -->
                  <!-- <el-dropdown-item command="8" v-if="scope.row.spread_uid">清除上级推广人</el-dropdown-item> -->
				  
				  <el-dropdown-item v-if="roles == 777" command="20" >删除</el-dropdown-item>
				  <div v-if="userFrom.user_type == 4">
					  <el-dropdown-item command="9" v-if="roles == 777 || roles == 10">添加学科卡密</el-dropdown-item>
					  
					  <el-dropdown-item command="15" v-if="roles == 777 || roles == 10">赠送阅读与听力</el-dropdown-item>
				  </div>
				  
				  <!-- <el-dropdown-item command="13" v-if="userFrom.user_type == 4 && roles == 777">添加听力练习</el-dropdown-item> -->
				  
				  <el-dropdown-item command="10" v-if="roles == 1">追加课程</el-dropdown-item>
				  
				  <el-dropdown-item command="11" v-if="roles == 1">修改学员年级</el-dropdown-item>
				  
				  <el-dropdown-item command="18" v-if="roles == 1 && scope.row.is_hearing == 2">添加用户听力</el-dropdown-item>
				  <el-dropdown-item command="19" v-if="roles == 1 && scope.row.is_reading == 2">添加用户阅读理解</el-dropdown-item>
				  
                </el-dropdown-menu>
              </el-dropdown>
            </template>
            <template v-else>
              <a v-db-click @click="userDetail(scope.row)">详情</a>
            </template>
          </template>
        </el-table-column>
      </el-table>

      <div class="acea-row row-right page">
        <pagination
          v-if="total"
          :total="total"
          :page.sync="userFrom.page"
          :limit.sync="userFrom.limit"
          @pagination="pageChange"
        />
      </div>
    </el-card>
    <!-- 编辑表单 积分余额-->
    <edit-from ref="edits" :FromData="FromData" @submitFail="submitFail"></edit-from>
    <!-- 发送优惠券-->
    <send-from ref="sends" :userIds="ids.toString()"></send-from>
    <!-- 会员详情-->
    <user-details ref="userDetails"></user-details>
    <!--发送图文消息 -->
    <el-dialog :visible.sync="modal13" title="发送消息" width="1200px" class="modelBox">
      <news-category
        v-if="modal13"
        :isShowSend="isShowSend"
        :userIds="ids.toString()"
        :scrollerHeight="scrollerHeight"
        :contentTop="contentTop"
        :contentWidth="contentWidth"
        :maxCols="maxCols"
      ></news-category>
    </el-dialog>
    <!--修改推广人-->
    <el-dialog :visible.sync="promoterShow" title="修改推广人" width="540px" :show-close="true">
      <el-form ref="formInline" :model="formInline" label-width="100px" @submit.native.prevent>
        <el-form-item v-if="formInline" label="选择推广人：" prop="image">
          <div class="picBox" v-db-click @click="customer">
            <div class="pictrue" v-if="formInline.image">
              <img v-lazy="formInline.image" />
            </div>
            <div class="upLoad acea-row row-center-wrapper" v-else>
              <i class="el-icon-user"></i>
            </div>
          </div>
        </el-form-item>
      </el-form>
      <div class="acea-row row-right mt20">
        <el-button v-db-click @click="cancel('formInline')">取消</el-button>
        <el-button type="primary" v-db-click @click="putSend('formInline')">提交</el-button>
      </div>
    </el-dialog>
    <el-dialog :visible.sync="customerShow" title="请选择商城用户" :show-close="true" width="1000px">
      <customerInfo v-if="customerShow" @imageObject="imageObject"></customerInfo>
    </el-dialog>
    <el-dialog :visible.sync="labelShow" title="请选择用户标签" width="540px" :show-close="true">
      <userLabel
        v-if="labelShow"
        :uid="labelActive.uid"
        :only_get="!labelActive.uid"
        @close="labelClose"
        @activeData="activeData"
        @onceGetList="onceGetList"
      ></userLabel>
    </el-dialog>
    <el-drawer :visible.sync="modals" :wrapperClosable="false" size="720" title="用户信息填写">
      <userEdit ref="userEdit" v-if="modals" :userData="userData"></userEdit>
      <div class="acea-row row-center">
        <el-button v-db-click @click="modals = false">取消</el-button>
        <el-button type="primary" v-db-click @click="setUser">提交</el-button>
      </div>
    </el-drawer>
    <!-- 用户标签 -->
    <el-dialog
      :visible.sync="selectLabelShow"
      title="请选择用户标签"
      width="540px"
      :show-close="true"
      :close-on-click-modal="false"
    >
      <userLabel
        v-if="selectLabelShow"
        :uid="0"
        ref="userLabel"
        :only_get="true"
        @activeData="activeSelectData"
        @close="labelClose"
      ></userLabel>
    </el-dialog>
	
	
	
	<!-- 添加学员课程 -->
	<el-dialog
	  title="添加学员课程"
	  :visible.sync="issubjectshow"
	  width="40%"
	  >
	  <div style="display: flex;">
		  <div style="width: 18%;padding-top: 5px;">选择所有科目</div>
		  <el-checkbox-group v-model="check_carmine_list" :max="zhuke_count" @change="zhukeChange" style="width: 460px;">
		     <el-checkbox v-for="(it, ix) in course_cate" :label="it.id">{{it.cate_name}}</el-checkbox>
		  </el-checkbox-group>
		  
	  </div>	  
	  <div style="display: flex;margin-top: 40px;">
		  <div style="width: 18%;padding-top: 5px;">选择副科</div>
		  <el-checkbox-group v-model="fu_check_carmine_list" style="width: 460px;" @change="fukeChange">
		     <el-checkbox v-for="(it, ix) in course_cate_fu" :label="it.id">{{it.cate_name}}</el-checkbox>
		  </el-checkbox-group>
	  </div>
	 <div v-if="activitygift > 0">
		 <div style="display: flex;margin-top: 40px;" >
			  <div style="width: 18%;padding-top: 5px;color: red;">选择活动副科</div>
			  <div>
				  <div style="margin-bottom: 10px;margin-top: 5px;color: red;">可以选择{{activitygift}}个科目</div>
				  <el-checkbox-group v-if="activity_gift_type == 1" v-model="new_zengsong_checkList" :max="activitygift"  style="width: 460px;">
				     <el-checkbox v-for="(it, ix) in course_cate" :label="it.id">{{it.cate_name}}</el-checkbox>
				  </el-checkbox-group>
				  <el-checkbox-group v-if="activity_gift_type == 2" v-model="new_zengsong_checkList" :max="activitygift"  style="width: 460px;">
				     <el-checkbox v-for="(it, ix) in course_cate" v-if="it.cate_type == 1" :label="it.id">{{it.cate_name}}</el-checkbox>
				  </el-checkbox-group>
				  <el-checkbox-group v-if="activity_gift_type == 3" v-model="new_zengsong_checkList" :max="activitygift"  style="width: 460px;">
				     <el-checkbox v-for="(it, ix) in course_cate" v-if="it.cate_type == 2" :label="it.id">{{it.cate_name}}</el-checkbox>
				  </el-checkbox-group>
			  </div>
			  
		  </div>
	 </div>
	  <span slot="footer" class="dialog-footer">
	    <el-button @click="issubjectshow = false">取 消</el-button>
	    <el-button type="primary" @click="student_add_subject">确 定</el-button>
	  </span>
	</el-dialog>
	
	
	
	<!-- 添加科目卡密 -->
	<div>
		
		<el-dialog
		  title="添加卡密"
		  :visible.sync="iscarmineshow"
		  width="50%"
		  :showClose="false"
		  :before-close="handleClose">
			
			<div style="display: flex;">
				<div style="font-size: 15px;width: 25%;margin-top: 5px;">生成卡密数量</div>
				<div style="width: 75%;">
					<!-- <el-input-number v-model="carmine_number" @focus="carmine_focus"  label="生成卡密数量" style="width: 200px;"></el-input-number> -->
					<el-input class="form-sty" v-model="carmine_number" placeholder="生成卡密数量"></el-input>
				</div>
			</div>

			<div style="display: flex;margin-top: 20px;">
				<div style="font-size: 15px;width: 25%;margin-top: 5px;">卡密类型</div>
				<div style="width: 75%;margin-top: 5px;">
					<el-radio-group v-model="subject_type" class="form-sty">
					  <el-radio :label="1">所有科目（语数英政历地物理化）</el-radio>
					  <el-radio :label="2">副科（政历地物理化）</el-radio>
					</el-radio-group>
				</div>
			</div>
			
			<div style="display: flex;margin-top: 20px;">
				<div style="font-size: 15px;width: 25%;margin-top: 5px;">卡密类型：</div>
				<div style="width: 75%;margin-top: 5px;">
					<el-radio-group v-model="type_two" class="form-sty">
					  <el-radio :label="1">付费</el-radio>
					  <el-radio :label="2">赠送</el-radio>
					  <el-radio :label="3">门票兑换</el-radio>
					  <el-radio :label="4">其他</el-radio>
					</el-radio-group>
				</div>
			</div>
			
			
			<div v-if="type_two == 4" style="display: flex;margin-top: 20px;">
				<div style="font-size: 15px;width: 25%;margin-top: 5px;">备注：</div>
				<div style="width: 60%;margin-top: 5px;">
					<!-- <input type="text" placeholder="请输入备注" style="border: 1px solid #cdcdcd;width: 100%;height: 30px;" /> -->
					
					<textarea
						  v-model="mask"
					      placeholder="请输入内容"
					      class="textarea-class"
					      style="height: 100px;width: 100%;border: 1px solid #cdcdcd;padding: 10px 10px;"
					    />
				</div>
			</div>
			
			
			
		
		  <span slot="footer" class="dialog-footer">
		    <el-button @click="iscarmineshow = false">取 消</el-button>
		    <el-button type="primary" @click="createCarmine">确 定</el-button>
		  </span>
		</el-dialog>
		
	</div>
	
	
	
	
	
	
	
	
	<div>
		
		<el-dialog
		  title="所有科学卡密"
		  :visible.sync="dialogVisible"
		  width="50%"
		  >
		    <div style="height: 400px;">
				<div class="card-item"  v-for="(item, index) in zhu_carmine_list" :key="index" style="padding: 10px 0;">
				  <el-checkbox-group v-model="checkList" @change="checkChangeFn(item.id, index, item)">
				       <el-checkbox :label="item.id">
				        <span style="width: 100%;">{{item.carmine_text }}</span>
				       </el-checkbox>
				   </el-checkbox-group>
				   <div v-if="item.is_check">
					   <div style="margin-top: 10px;">
						   <el-radio-group v-model="zhu_carmine_list[index]['subject_name']">
						      <el-radio :label="it.cate_name" v-for="(it, ix) in course_cate" style="padding: 5px;">{{it.cate_name}}</el-radio>
						   </el-radio-group>
					    </div>
				   </div>
				</div>	
			</div>	  
		  <span slot="footer" class="dialog-footer">
		    <el-button @click="dialogVisible = false">取 消</el-button>
		    <el-button type="primary" @click="allsubject">确 定</el-button>
		  </span>
		</el-dialog>
		
	</div>
	
	
	
	
	
	<div>
		<el-dialog
		  title="副科卡密"
		  :visible.sync="dialogVisibleTwo"
		  width="50%"
		  >
		  <div style="height: 400px;">
		    <div class="card-item"  v-for="(item, index) in fu_carmine_list" :key="index" style="padding: 10px 0;">
		      <el-checkbox-group v-model="checkList" @change="checkChangeFntwo(item.id, index, item)">
		           <el-checkbox :label="item.id">
		            <span style="width: 100%;">{{item.carmine_text }}</span>
		           </el-checkbox>
		       </el-checkbox-group>
			   <div v-if="item.is_check">
				   <div style="margin-top: 10px;">
					   <el-radio-group v-model="fu_carmine_list[index]['subject_name']" style="display: flex;flex-wrap: wrap;">
						   <div v-for="(it, ix) in course_cate">
							   <el-radio v-if="it.cate_type == 2" :label="it.cate_name" style="padding: 5px;">{{it.cate_name}}</el-radio>
							   <el-radio v-else disabled :label="it.cate_name" style="padding: 5px;">{{it.cate_name}}</el-radio>
						   </div>
					      
					   </el-radio-group>
				    </div>
			   </div>
		    </div>
			</div>		  
		  <span slot="footer" class="dialog-footer">
		    <el-button @click="dialogVisibleTwo = false">取 消</el-button>
		    <el-button type="primary" @click="fusubject">确 定</el-button>
		  </span>
		</el-dialog>
		
	</div>
	
	<!-- //活动副科选择 -->
	<div>
		<el-dialog
		  title="活动赠送副科"
		  :visible.sync="dialogVisiblezengsong"
		  width="50%"
		  >
		    
			
			<div style="text-align: center;font-size: 18px;margin-bottom: 10px;">可以选择{{activitygift}}科</div>
			
			<el-checkbox-group v-model="zengsong_checkList" :max="activitygift">
			    <el-checkbox v-for="(item, index) in course_cate" v-if="item.cate_type == 2" :label="item.cate_name" key="item.id"></el-checkbox>
			  </el-checkbox-group>	
				
			
				  
		  <span slot="footer" class="dialog-footer">
		    <el-button @click="dialogVisiblezengsong = false">取 消</el-button>
		    <el-button type="primary" @click="hudongsubject">确 定</el-button>
		  </span>
		</el-dialog>
		
	</div>
	
	
	<!-- 代理商修改学员年级 -->
	<div>
		<el-dialog
		  title="修改学员年级"
		  :visible.sync="editStudentClass"
		  width="50%"
		  >
		    <div>选择用户所属年级</div>
			<div style="margin-top: 20px;">
				<el-radio-group v-model="now_edit_class">
				    <el-radio :label="1">初一</el-radio>
				    <el-radio :label="2">初二</el-radio>
				    <el-radio :label="3">初三</el-radio>
				    <el-radio :label="7">初四</el-radio>
					<el-radio :label="4">高一</el-radio>
					<el-radio :label="5">高二</el-radio>
					<el-radio :label="6">高三</el-radio>
				</el-radio-group>
			</div>
				  
		  <span slot="footer" class="dialog-footer">
		    <el-button @click="editStudentClass = false">取 消</el-button>
		    <el-button type="primary" @click="edit_student_class">确 定</el-button>
		  </span>
		</el-dialog>
		
	</div>
	
	
	
	<el-dialog
	  title="赠送听力阅读理解"
	  :visible.sync="giftcourse"
	  width="30%"
	  :before-close="handleClose">
	  
	  <div style="font-size: 16px;margin-bottom: 20px;">听力 -> 当前剩余：{{gift_user_info.hearing_count}}次</div>
	  
	  <div style="display: flex;">
		  <div style="width: 80px;">类型</div>
		  <div>
			  <el-radio v-model="hearing_type" label="1">增加</el-radio>
			  <el-radio v-model="hearing_type" label="2">减少</el-radio>
		  </div>
	  </div>
	  
	  <div style="display: flex;margin-top: 20px;">
		  <div style="width: 80px;margin-top: 5px;">数量</div>
		  <div>
			  <el-input v-model="hearing_count" placeholder="请输入数量"></el-input>
		  </div>
	  </div>
	  

	  
	  <div style="font-size: 16px;margin-bottom: 20px;margin-top: 20px;">阅读理解 -> 当前剩余：{{gift_user_info.reading_count}}次</div>
	  
	  <div style="display: flex;">
	  		  <div style="width: 80px;">类型</div>
	  		  <div>
	  			  <el-radio v-model="reading_type" label="1">增加</el-radio>
	  			  <el-radio v-model="reading_type" label="2">减少</el-radio>
	  		  </div>
	  </div>
	  
	  <div style="display: flex;margin-top: 20px;">
	  		  <div style="width: 80px;margin-top: 5px;">数量</div>
	  		  <div>
	  			  <el-input v-model="reading_count" placeholder="请输入数量"></el-input>
	  		  </div>
	  </div>
	  
	  <span slot="footer" class="dialog-footer">
	    <el-button @click="giftcourse = false">取 消</el-button>
	    <el-button type="primary" @click="submitgiftreading">确 定</el-button>
	  </span>
	</el-dialog>
	
	
  </div>
</template>

<script>
import userLabel from '@/components/userLabel';
import { mapState } from 'vuex';
import expandRow from './tableExpand.vue';
import userEdit from './handle/userEdit.vue';
import {
  userList,
  allUserDisableApi,
  getUserData,
  isShowApi,
  editOtherApi,
  giveLevelApi,
  userSetGroup,
  userGroupApi,
  levelListApi,
  userSetLabelApi,
  userLabelApi,
  userSynchro,
  getUserSaveForm,
  giveLevelTimeApi,
  getUserInfo,
  setUser,
  editUser,
  saveSetLabel,
  userSaveTatusDisableApi,
  getAllSubjectApi,
  setChgenerateCarmine,
  userCourseBatchDisable,
  allUserCourseBatchDisable,
  getAgentAllCarmineApi,
  studentAddSubjectApi,
  editStudentClassApi,
  giftreadinghearing,
  setUserHearing,
  deleteUserInfo
} from '@/api/user';
import { getcoursecatelist,carmineActivity } from '@/api/product';
import { agentSpreadApi } from '@/api/agent';
import { exportUserList } from '@/api/export';
import editFrom from '../../../components/from/from';
import sendFrom from '@/components/sendCoupons/index';
import userDetails from './handle/userDetails';
import newsCategory from '@/components/newsCategory/index';
import customerInfo from '@/components/customerInfo';
import { cityList } from '@/api/app';

export default {
  name: 'user_list',
  components: {
    expandRow,
    editFrom,
    sendFrom,
    userDetails,
    newsCategory,
    customerInfo,
    userLabel,
    userEdit,
  },
  data() {
    return {
		groupinglist:[],
		mask:'',  //beizh
	zhuke_count:0,  //代理商主科的卡密数量
	check_subject_info:{},  //用户数据
		
	hearing_type:'1',  //增加听力类型  1是增加  2是减少	
	hearing_count:'', //听力的次数
	reading_type:'1', //阅读理解的类型 1是增加 2是减少
	reading_count:'', //阅读理解的次数
	gift_user_info:{},
	
	giftcourse:false,	
		
	activity_gift_type:3,  //活动赠送科目类型  1是全部  2是只主科  3是只副科
	activitygift:0,  //活动赠送数量
	huodong_number:0,  //选择活动赠送科目的数量
	
	activity_list:[],  //卡密活动列表		
	zengsong_checkList: [],  //选择活动赠送的副科
	new_zengsong_checkList:[],  //提交的活动卡密	
	
	editStudentClass:false,
	now_edit_class:0,  //要修改年级的用户现在所属年级
	now_edit_class_uid:0,  //要修改年级的用户id 
		
	
	check_subject_uid:0,  //添加课程的用户ID
	zong_zhu_carmine_list:[],
	zong_fu_carmine_list:[],
	zhu_carmine_list:[],
	fu_carmine_list:[],
	course_cate:[],
	course_cate_fu:[],
	
	check_carmine_list:[],  //添加学员所有学科选择
	fu_check_carmine_list:[],  //添加学员所有学科选择
	
	
	
	checkList:[],
	dialogVisible: false,
	dialogVisibleTwo:false,	
	dialogVisiblezengsong:false,	
		
	  
	  issubjectshow:false,
	  
	  
	  roles:0,  //管理员权限	  
		
		
	  course_cate_list:[],  //课程分类列表	
		
	  iscarmineshow:false,
	  carmine_number: '',  //生成卡密的数量
	  subject_type:1,  //所选课程类型  1是所有学科  2 是副科
	  type_two:1,  //所选课程类型  1是所有学科  2 是副科
	  // subject_list: [],  //选择科目列表
	  // gift_subject_list: [],  //赠送的科目列表
   //    become_time:1,  //激活后到期时间  天
	  now_uid:0,  //当前选择的用户
		
      dataLabel: [],
      selectDataLabel: [],
      userData: {},
      modals: false,
      selectLabelShow: false,
      labelShow: false,
      customerShow: false,
      promoterShow: false,
      labelActive: {
        uid: 0,
      },
      formInline: {
        uid: 0,
        spread_uid: 0,
        image: '',
      },
      pickerOptions: this.$timeOptions,
      collapse: false,
      headeNum: [
        // { type: '', name: '全部' },
        { type: '1', name: '学员' },
        // { type: '2', name: '教师' },
        // { type: '3', name: '员工' },
        { type: '4', name: '经销商' },
      ],
      address: [],
      addresData: [],
      isShowSend: true,
      modal13: false,
      maxCols: 4,
      scrollerHeight: '600',
      contentTop: '130',
      contentWidth: '98%',
      grid: {
        xl: 6,
        lg: 6,
        md: 8,
        sm: 12,
        xs: 24,
      },
      grid2: {
        xl: 8,
        lg: 8,
        md: 8,
        sm: 12,
        xs: 24,
      },
      loading: false,
      total: 0,
      userFrom: {
        label_id: '',
        user_type: '1',
        status: '',
		belong_subject:'', //所属科目
		is_activity:'', //是否享受活动
		agent_grouping_id:'', //所属分组
        sex: '',
        is_promoter: '',
        country: '',
        isMember: '',
        pay_count: '',
        user_time_type: '',
        user_time: '',
        nickname: '',
        province: '',
        city: '',
        page: 1,
        limit: 15,
        level: '',
        group_id: '',
        field_key: '',
		class:'',  //所属年级
      },
      field_key: '',
      level: '',
      group_id: '',
      label_id: '',
      user_time_type: '',
      pay_count: '',
      userLists: [],
      FromData: null,
      selectionList: [],
      user_ids: '',
      selectedData: [],
      timeVal: [],
      groupList: [],
      levelList: [],
      labelFrom: {
        page: 1,
        limit: '',
      },
      labelLists: [],
      selectedIds: [], //选中合并项的id
      ids: [],
    };
  },
  computed: {
    ...mapState('media', ['isMobile']),
  },
  created() {
    this.getList();
    this.getCityList();
	this.getAllSubjectApi(); //获取所有科目列表
	this.getAgentAllCarmineApi();
	this.carmineActivity();
  },
  mounted() {
    this.userGroup();
    this.levelLists();
    // this.groupLists();
  },
  methods: {
	
	//选中主科时候的选择活动
	zhukeChange(e){
		// this.check_carmine_list = e
		this.activitygift = 0;
		this.activity_gift_type = 3;
		this.new_zengsong_checkList = [];

		var zhuCount = 0;
		for(var i=0;i<e.length;i++){
			if(e[i] == 4 || e[i] == 5 || e[i] == 6 || e[i] == 7 || e[i] == 8 || e[i] == 9){
				zhuCount++
			}
		}
		if(this.activity_list.length > 0 && zhuCount > 0){
			for(var i = 0;i<this.activity_list.length;i++){
				if(zhuCount == this.activity_list[i].major_number){
					console.log(this.activity_list[i].major_number);
					this.activitygift = this.activity_list[i].minor_number;
					this.activity_gift_type = this.activity_list[i].gift_type;
				}
			}
		}
	},  
	  
	
	//提交增加听力和阅读理解
	submitgiftreading(){
		
		// hearing_type:'1',  //增加听力类型  1是增加  2是减少
		// hearing_count:'', //听力的次数
		
		
		// reading_type:'1', //阅读理解的类型 1是增加 2是减少
		// reading_count:'', //阅读理解的次数
		
		
		if(this.hearing_count == '' && this.reading_count == ''){
			this.$message.error('请输入数量');
		}
		
		giftreadinghearing({
			hearing_type:this.hearing_type,
			hearing_count:this.hearing_count,
			reading_type:this.reading_type,
			reading_count:this.reading_count,
			gift_uid:this.gift_user_info.uid
		})
		  .then((res) => {
			  this.giftcourse = false;
			this.$message({
				type: 'success',
				message: '操作成功!'
			});
			this.getList()
			
			
		  })
		  .catch((res) => {
		    this.$message.error(res.msg);
		  });
	},  
	  
	
	//活动副科提交
	hudongsubject(){
		console.log(this.zengsong_checkList);
		if(this.zengsong_checkList.length > 0){
			this.huodong_number = this.zengsong_checkList.length
			this.new_zengsong_checkList = this.zengsong_checkList;
		}
		
		this.dialogVisiblezengsong = false;
	},  
	  
	
	carmineActivity(){
		var that = this
		carmineActivity()
		  .then((res) => {
			
				that.activity_list = res.data.list
		  })
		  .catch((res) => {
		    this.$message.error(res.msg);
		  });
	},
	  
	//代理商给用户修改年级
	edit_student_class(){
		
		editStudentClassApi({
			now_edit_class:this.now_edit_class,
			now_edit_class_uid:this.now_edit_class_uid,
		})
		.then((res) => {
			this.editStudentClass = false;
			this.$message({
				type: 'success',
				message: '提交审核成功!'
			});
			this.getList()
		})
		.catch((res) => {
		  this.$message.error(res.msg);
		});
	}, 
	  
	
	
	//代理商给学员添加科目
	student_add_subject(){
		studentAddSubjectApi({
			check_subject_uid:this.check_subject_uid,
			check_carmine_list:this.check_carmine_list,
			fu_check_carmine_list:this.fu_check_carmine_list,
			huodong_carmine_list:this.new_zengsong_checkList,
		})
		.then((res) => {
			// this.iscarmineshow = false;
			this.issubjectshow = false;
			this.$message({
				type: 'success',
				message: '提交审核成功!'
			});
			this.getList()
		})
		.catch((res) => {
		  this.$message.error(res.msg);
		});
	
	},
	
	//副科提交
	fusubject(){
		for(var i=0;i<this.fu_carmine_list.length;i++){
			if(this.fu_carmine_list[i]['is_check']){
				//判断是否选择学科
				if(this.fu_carmine_list[i]['subject_name'] == ''){
					this.$message.error('请选择具体科目');
					return false;
				}
				var base = {
					'carmine_text':this.fu_carmine_list[i]['carmine_text'],
					'id':this.fu_carmine_list[i]['id'],
					'subject_name':this.fu_carmine_list[i]['subject_name'],
				}
				this.fu_check_carmine_list.push(base)
			}
		}
		// this.formItem.fu_check_carmine_list = this.fu_check_carmine_list
		this.dialogVisibleTwo = false;
	},
	
	//所有学科提交
	allsubject(){
		for(var i=0;i<this.zhu_carmine_list.length;i++){
			if(this.zhu_carmine_list[i]['is_check']){
				//判断是否选择学科
				if(this.zhu_carmine_list[i]['subject_name'] == ''){
					this.$message.error('请选择具体科目');
					return false;
				}
				var base = {
					'carmine_text':this.zhu_carmine_list[i]['carmine_text'],
					'id':this.zhu_carmine_list[i]['id'],
					'subject_name':this.zhu_carmine_list[i]['subject_name'],
				}
				this.check_carmine_list.push(base)
			}
		}
	

		let zhuCount = 0
		for(var i=0;i<this.check_carmine_list.length;i++){
			var subject_name = this.check_carmine_list[i].subject_name;
			if(subject_name == '高中语文' || subject_name == '高中数学' || subject_name == '高中英语' || subject_name == '初中语文' || subject_name == '初中数学' || subject_name == '初中英语'){
				console.log('进入这里');
				zhuCount++
			}
		}
		console.log(zhuCount);

		
		//判断有没有活动  activity_list
		
		console.log(zhuCount);
		console.log(this.activity_list);
		
		if(this.activity_list.length > 0 && zhuCount > 0){
			console.log('baga11111111');
			for(var i = 0;i<this.activity_list.length;i++){
				console.log('baga');
				if(zhuCount == this.activity_list[i].major_number){
					console.log('进入赠送');
					console.log(this.activity_list[i].major_number);
					this.activitygift = this.activity_list[i].minor_number;
				}
			}
		}
		
		console.log('赠送数量');
		console.log(this.activitygift);
		
		this.dialogVisible = false;
	},
	
	//选择多选框
	checkChangeFn(id,index,item){
		this.zhu_carmine_list[index]['is_check'] = !this.zhu_carmine_list[index]['is_check'];
	},  
	
	checkChangeFntwo(id,index,item){
		this.fu_carmine_list[index]['is_check'] = !this.fu_carmine_list[index]['is_check'];
	},
	  
	  
	  //获取当前代理商所有的卡密
	  getAgentAllCarmineApi(){
	  	var that = this
	  	getAgentAllCarmineApi()
	  	  .then((res) => {
			
	  		  that.zhu_carmine_list = res.data.zhu_carmine_list
	  		  that.fu_carmine_list = res.data.fu_carmine_list
	  		  that.course_cate = res.data.course_cate
	  		  that.course_cate_fu = res.data.course_cate_fu
	  		  that.zong_zhu_carmine_list = res.data.zhu_carmine_list
	  		  that.zong_fu_carmine_list = res.data.fu_carmine_list
			  that.zhuke_count = res.data.zhuke_count	
			  console.log('完成之后--------------');
			  console.log(that.zhu_carmine_list);
			  console.log(that.fu_carmine_list);
			  console.log('完成之后--------------');
	  	  })
	  	  .catch((res) => {
	  	    this.$message.error(res.msg);
	  	  });
	  },
	  
	  
	  
	  
	  
	createCarmine(){
		
		if(this.carmine_number == ''){
			this.$message({
			  message: '请输入卡密数量',
			  type: 'warning'
			});
			return false;
		}
		this.carmine_number = Number(this.carmine_number);
		
		
		var base = Number.isFinite(this.carmine_number);
		
		if(!base){
			this.$message({
			  message: '请输入正确的卡密数量整数',
			  type: 'warning'
			});
			return false;
		}
		
		var that = this
		setChgenerateCarmine({
			carmine_number:that.carmine_number,
			subject_type:that.subject_type,
			type_two:that.type_two,
			now_uid:that.now_uid,
			mask:that.mask
		})
		.then((res) => {
			this.iscarmineshow = false;
			this.$message({
				type: 'success',
				message: '添加成功!'
			});
			this.getList()
		})
		.catch((res) => {
		  this.$message.error(res.msg);
		});
		
	},  
	
	
	//获取所有科目
	getAllSubjectApi(){
		var that = this
		getAllSubjectApi({})
		.then((res) => {
			that.course_cate_list = res.data.list
		})
		.catch((res) => {
		  this.$message.error(res.msg);
		});
	},
	
	  
	  
	handleClose(done) {
		this.$confirm('确认关闭？')
		  .then(_ => {
			done();
		})
		.catch(_ => {});
	}, 
	
	//全部禁用
	batch_disable_all(){
		this.$confirm('确定要将所有账号全部禁用嘛?', '提示', {
		  confirmButtonText: '确定',
		  cancelButtonText: '取消',
		  type: 'warning'
		}).then(() => {
			
			allUserDisableApi(this.userFrom)
			.then((res) => {
				this.$message({
					type: 'success',
					message: '设置成功!'
				});
				this.getList()
			})
			.catch((res) => {
			  this.$message.error(res.msg);
			});
			
		  
		}).catch(() => {
		         
		});
	},
	
	//所有学员课程禁用
	all_course_batch_disable(){
		this.$confirm('确定要将所有学员的课程禁用嘛?', '提示', {
		  confirmButtonText: '确定',
		  cancelButtonText: '取消',
		  type: 'warning'
		}).then(() => {
			
			allUserCourseBatchDisable()
			.then((res) => {
				this.$message({
					type: 'success',
					message: '设置成功!'
				});
				this.getList()
			})
			.catch((res) => {
			  this.$message.error(res.msg);
			});
			
		  
		}).catch(() => {
				 
		});
	},
	
	//学员课程禁用
	course_batch_disable(){
		if (this.ids.length === 0) {
		  this.$message.warning('请选择要设置禁用课程的账号');
		} else {
		  let uids = { uids: this.ids };	
			console.log('查看参数-------------------------');
			console.log(uids);
			console.log('查看参数-------------------------');
		
			 this.$confirm('确定要将所选学员的课程禁用嘛?', '提示', {
			  confirmButtonText: '确定',
			  cancelButtonText: '取消',
			  type: 'warning'
			}).then(() => {
				
				userCourseBatchDisable(uids)
				.then((res) => {
					this.$message({
						type: 'success',
						message: '设置成功!'
					});
					this.getList()
				})
				.catch((res) => {
				  this.$message.error(res.msg);
				});
				
			  
			}).catch(() => {
					 
			});
				
		}
	},
	  
	
	// 批量设置禁用账号
	batch_disable() {
	  if (this.ids.length === 0) {
	    this.$message.warning('请选择要设置禁用账号');
	  } else {
	    let uids = { uids: this.ids };	
		console.log('查看参数-------------------------');
		console.log(uids);
		console.log('查看参数-------------------------');
	
		 this.$confirm('确定要将所选账号全部禁用嘛?', '提示', {
		  confirmButtonText: '确定',
		  cancelButtonText: '取消',
		  type: 'warning'
		}).then(() => {
			
			userSaveTatusDisableApi(uids)
			.then((res) => {
				this.$message({
					type: 'success',
					message: '设置成功!'
				});
				this.getList()
			})
			.catch((res) => {
			  this.$message.error(res.msg);
			});
			
		  
		}).catch(() => {
		         
		});
		
	  }
	},
	  
	  
    getCityList() {
      cityList().then((res) => {
        this.addresData = res.data;
        this.groupinglist = res.data.groupinglist;
      });
    },
    setUser() {
      let data = this.$refs.userEdit.formItem;
      let ids = [];
      this.$refs.userEdit.dataLabel.map((i) => {
        ids.push(i.id);
      });
      data.label_id = ids;
      // if (!data.real_name) return this.$message.warning("请输入真实姓名");
      // if (!data.phone) return this.$message.warning("请输入手机号");
      // if (!data.pwd) return this.$message.warning("请输入密码");
      // if (!data.true_pwd) return this.$message.warning("请输入确认密码");
      if (data.uid) {
        editUser(data)
          .then((res) => {
            this.modals = false;
            this.$message.success(res.msg);
            this.getList();
          })
          .catch((err) => {
            this.$message.error(err);
          });
      } else {
        setUser(data)
          .then((res) => {
            this.modals = false;
            this.$message.success(res.msg);
            this.getList();
          })
          .catch((err) => {
            this.$message.error(err.msg);
          });
      }
    },
    onceGetList() {
      this.labelActive.uid = 0;
      this.getList();
    },
    // 标签弹窗关闭
    labelClose() {
      this.labelActive.uid = 0;
      this.labelShow = false;
      this.selectLabelShow = false;
    },
    // 提交
    putSend(name) {
      this.$refs[name].validate((valid) => {
        if (valid) {
          if (!this.formInline.spread_uid) {
            return this.$message.error('请上传用户');
          }
          agentSpreadApi(this.formInline)
            .then((res) => {
              this.promoterShow = false;
              this.$message.success(res.msg);
              this.getList();
              this.$refs[name].resetFields();
            })
            .catch((res) => {
              this.$message.error(res.msg);
            });
        }
      });
    },

    save() {
      this.modals = true;

      // this.$modalForm(getUserSaveForm())
      //   .then(() => {
      //     this.userFrom.page = 1;
      //     this.getList();
      //   })
      //   .catch((res) => {
      //     this.$message.error(res.msg);
      //   });
    },
    synchro() {
      userSynchro()
        .then((res) => {
          this.$message.success(res.msg);
        })
        .catch((res) => {
          this.$message.error(res.msg);
        });
    },
    isSel(row) {
      return !!!row.is_del;
    },
    // 分组列表
    groupLists() {
      this.loading = true;
      userLabelApi(this.labelFrom)
        .then(async (res) => {
          let data = res.data;
          this.labelLists = data.list;
        })
        .catch((res) => {
          this.loading = false;
          this.$message.error(res.msg);
        });
    },
    onClickTab() {
      this.userFrom.page = 1;
      this.getList();
    },
    userGroup() {
      let data = {
        page: 1,
        limit: '',
      };
      userGroupApi(data).then((res) => {
        this.groupList = res.data.list;
      });
    },
	
	
	
    levelLists() {
      // let data = {
      //   page: 1,
      //   limit: '',
      //   title: '',
      //   is_show: 1,
      // };
      // levelListApi(data).then((res) => {
      //   this.levelList = res.data.list;
      // });
	  
	  getcoursecatelist()
		.then((res) => {
			this.levelList = res.data
		  // this.treeSelect = res.data;
		})
		.catch((res) => {
		  this.$message.error(res.msg);
		});

	  
    },
	
	
	
	
    // 批量设置分组；
    setGroup() {
      if (this.ids.length === 0) {
        this.$message.warning('请选择要设置分组的用户');
      } else {
        let uids = { uids: this.ids };
        this.$modalForm(userSetGroup(uids)).then(() => {
          this.ids = [];
          this.selectedIds = [];
          this.getList();
        });
      }
    },
    // 批量设置标签；
    setLabel() {
      if (this.ids.length === 0) {
        this.$message.warning('请选择要设置标签的用户');
      } else {
        let uids = { uids: this.ids };
        this.labelActive.uid = 0;
        this.labelShow = true;
        // this.$modalForm(userSetLabelApi(uids)).then(() =>
        //   this.$refs.sends.getList()
        // );
      }
    },
    activeSelectData(data) {
      this.selectLabelShow = false;
      this.selectDataLabel = data || [];
      if (this.selectDataLabel.length) {
        let activeIds = [];
        this.selectDataLabel.map((item) => {
          activeIds.push(item.id);
        });
        this.userFrom.label_id = activeIds.join(',');
      } else {
        this.userFrom.label_id = '';
      }
    },
    handleClose(tag) {
      let i = this.selectDataLabel.findIndex((item) => item.id === tag.id);
      if (i !== -1) {
        this.selectDataLabel.splice(i, 1);
      }
      this.$nextTick(() => {
        if (this.selectDataLabel.length) {
          let activeIds = [];
          this.selectDataLabel.map((item) => {
            activeIds.push(item.id);
          });
          this.userFrom.label_id = activeIds.join(',');
        } else {
          this.userFrom.label_id = '';
        }
      });
      // this.userSearchs();
    },
    // 批量设置标签
    activeData(data) {
      let labels = [];
      if (!data.length) return;
      data.map((i) => {
        labels.push(i.id);
      });
      saveSetLabel({
        uids: this.ids.join(','),
        label_id: labels,
      }).then((res) => {
        this.labelShow = false;
        this.selectedIds = new Set();
        this.getList();
        this.$message.success(res.msg);
      });
    },
    //是否为付费会员；
    changeMember() {
      this.userFrom.page = 1;
      this.getList();
    },
    // 选择国家
    changeCountry() {
      if (this.userFrom.country === 'abroad' || !this.userFrom.country) {
        this.selectedData = [];
        this.userFrom.province = '';
        this.userFrom.city = '';
        this.address = [];
      }
    },
	

	
    // 选择地址
    handleChange(selectedData) {
      this.selectedData = selectedData.map((o) => o.label);
      this.userFrom.province = this.selectedData[0];
      this.userFrom.city = this.selectedData[1];
    },
    // 具体日期
    onchangeTime(e) {
      this.timeVal = e;
      this.userFrom.user_time = this.timeVal ? this.timeVal.join('-') : '';
    },
    userDetail(row) {
      this.$refs.userDetails.modals = true;
      this.$refs.userDetails.getDetails(row.uid);
    },
    // 操作
    changeMenu(row, name, index) {
      let uid = [];
      uid.push(row.uid);
      let uids = { uids: uid };
      switch (name) {
        case '1':
          this.edit(row);
          break;
        case '2':
          this.getOtherFrom(row.uid);
          break;
        case '3':
          this.giveLevelTime(row.uid);
          break;
        case '4':
          this.del(row, '清除 【 ' + this.tenText(row.nickname) + ' 】的会员等级', index, 'user');
          break;
        case '5':
          this.$modalForm(userSetGroup(uids)).then(() => this.getList());
          break;
        case '6':
          this.openLabel(row);
          break;
        case '7':
          this.editS(row);
          break;
		case '9':
		  console.log('添加卡密');
		  console.log(row.uid);
		  console.log('添加卡密');
		
		  
		  this.carmine_number = ''
		  this.subject_list = []
		  this.gift_subject_list = []
		  this.become_time = 1
		  this.mask = '';
		  this.now_uid = row.uid
		  this.type_two = 1
		  this.iscarmineshow = !this.iscarmineshow
		  break;
		case '10':
			this.check_carmine_list = [];
			this.fu_check_carmine_list = []
			this.checkList = [];
			this.check_subject_uid = row.uid
			
			this.zengsong_checkList = [];
			this.new_zengsong_checkList = [];
			this.activitygift = 0;
			
			this.check_subject_info = row
			
			this.getAgentAllCarmineApi();
			this.issubjectshow = true;
			
		    break;
		case '11':
				this.now_edit_class = row.class
				this.now_edit_class_uid = row.uid
				this.editStudentClass = true;
			    break;
		case '15':
				this.gift_user_info = row;
				this.giftcourse = true;
			    break;		
		case '18':
				var that = this
				 this.$confirm('确定要给用户追加听力吗?', '提示', {
				  confirmButtonText: '确定',
				  cancelButtonText: '取消',
				  type: 'warning'
				}).then(() => {
				  
				  console.log('0000000000000000000000');
				  
				  setUserHearing({
					  uid:row.uid,
					  type:1
				  }).then((res) => {
					  that.getList();
					  that.$message.success('设置成功');
				  }).catch((res) => {
					  that.$message.error(res.msg);
				  });
				  
				}).catch(() => {
				          
				});
				
			    break;	
		case '19':
				var that = this
				 this.$confirm('确定要给用户追加阅读理解吗?', '提示', {
				  confirmButtonText: '确定',
				  cancelButtonText: '取消',
				  type: 'warning'
				}).then(() => {
				  
				  console.log('0000000000000000000000');
				  
				  setUserHearing({
					  uid:row.uid,
					  type:2
				  }).then((res) => {
					  that.getList();
					  that.$message.success('设置成功');
				  }).catch((res) => {
					  that.$message.error(res.msg);
				  });
				  
				}).catch(() => {
				          
				});
			    break;		
		case '20':
				var that = this
				 this.$confirm('确定要删除该用户嘛?', '提示', {
				  confirmButtonText: '确定',
				  cancelButtonText: '取消',
				  type: 'warning'
				}).then(() => {
				  
				  
				  
				  deleteUserInfo({
					  uid:row.uid
				  }).then((res) => {
					  that.$message.success('删除成功');
					   that.getList();
				  }).catch((res) => {
					  that.$message.error(res.msg);
				  });
				  
				}).catch(() => {
				          
				});
			    break;				
				
        default:
          this.del(row, '解除【 ' + this.tenText(row.nickname) + ' 】的上级推广人', index, 'tuiguang');
      }
    },
    tenText(str) {
      if (str.length > 10) {
        //如果字符长度超过10，后面的字符就变成...可自行调整长度和代替字符
        str = str.substr(0, 10) + '...'; //截取从第一个字符开始，往后取10个字符，剩余的用...代替
      }
      return str;
    },
    openLabel(row) {
      this.labelShow = true;
      this.labelActive.uid = row.uid;
    },
    openSelectLabel() {
      this.selectLabelShow = true;
    },
    editS(row) {
      this.promoterShow = true;
      this.formInline.uid = row.uid;
    },
    customer() {
      this.customerShow = true;
    },
    imageObject(e) {
      this.customerShow = false;
      this.formInline.spread_uid = e.uid;
      this.formInline.image = e.image;
    },
    cancel(name) {
      this.promoterShow = false;
      this.$refs[name].resetFields();
      this.formInline = {
        uid: 0,
        spread_uid: 0,
        image: '',
      };
    },
    // 赠送会员等级
    giveLevel(id) {
      this.$modalForm(giveLevelApi(id)).then(() => this.getList(1));

      // giveLevelApi(id)
      //   .then(async (res) => {
      //     if (res.data.status === false) {
      //       return this.$authLapse(res.data);
      //     }

      //     this.FromData = res.data;
      //     this.$refs.edits.modals = true;
      //   })
      //   .catch((res) => {
      //     this.$message.error(res.msg);
      //   });
    },
    // 赠送会员等级
    giveLevelTime(id) {
      this.$modalForm(giveLevelTimeApi(id)).then(() => this.getList(1));

      // giveLevelTimeApi(id)
      //   .then(async (res) => {
      //     if (res.data.status === false) {
      //       return this.$authLapse(res.data);
      //     }
      //     this.FromData = res.data;
      //     this.$refs.edits.modals = true;
      //   })
      //   .catch((res) => {
      //     this.$message.error(res.msg);
      //   });
    },
    // 删除
    del(row, tit, num, name) {
      let delfromData = {
        title: tit,
        num: num,
        url: name === 'user' ? `user/del_level/${row.uid}` : `agent/stair/delete_spread/${row.uid}`,
        method: name === 'user' ? 'DELETE' : 'PUT',
        ids: '',
        width: 600,
      };
      this.$modalSure(delfromData)
        .then((res) => {
          this.$message.success(res.msg);
          this.getList();
        })
        .catch((res) => {
          this.$message.error(res.msg);
        });
    },
    // 清除会员删除成功
    submitModel() {
      this.getList();
    },
    // 会员列表
    getList() {
      // if (this.selectDataLabel.length) {
      //   let activeIds = [];
      //   this.selectDataLabel.forEach((item) => {
      //     activeIds.push(item.id);
      //   });
      //   this.userFrom.label_id = activeIds.join(',');
      // }
      this.userFrom.user_type = this.userFrom.user_type || '';
      this.userFrom.status = this.userFrom.status || '';
      this.userFrom.belong_subject = this.userFrom.belong_subject || '';
      this.userFrom.is_activity = this.userFrom.is_activity || '';
	  this.userFrom.class = this.userFrom.class || '';
	  
	  
      this.userFrom.sex = this.userFrom.sex || '';
      this.userFrom.is_promoter = this.userFrom.is_promoter || '';
      this.userFrom.country = this.userFrom.country || '';
      this.userFrom.pay_count = this.pay_count === 'all' ? '' : this.pay_count;
      this.userFrom.user_time_type = this.user_time_type === 'all' ? '' : this.user_time_type;
      this.userFrom.field_key = this.field_key === 'all' ? '' : this.field_key;
      this.userFrom.level = this.level === 'all' ? '' : this.level;
      this.userFrom.group_id = this.group_id === 'all' ? '' : this.group_id;
      this.loading = true;
      userList(this.userFrom)
        .then(async (res) => {
          let data = res.data;
          this.userLists = data.list;
		  
		  this.roles = data.roles
		  
		  if(this.roles == 1){
			this.headeNum = [
				// { type: '1', name: '学员' },
			];
			this.userFrom.user_type = 1
		  }
		  
		  if(this.roles == 777){
			this.headeNum =  [
				// { type: '', name: '全部' },
				{ type: '1', name: '学员' },
				// { type: '2', name: '教师' },
				// { type: '3', name: '区代理' },
				{ type: '4', name: '经销商' },
			];
		  }
		  
		  if(this.roles == 10){
			this.headeNum =  [
				// { type: '', name: '全部' },
				{ type: '1', name: '学员' },
				// { type: '2', name: '教师' },
				// { type: '3', name: '区代理' },
				{ type: '4', name: '经销商' },
			];
		  }
		  
	
			  
          this.total = data.count;
          this.loading = false;
          this.$nextTick(() => {
            this.setChecked();
          });
        })
        .catch((res) => {
          this.loading = false;
          this.$message.error(res.msg);
        });
    },
    // 用户导出
    async exportList() {
      if (this.ids.length) {
        this.userFrom.ids = this.ids;
      }
      this.userFrom.user_type = this.userFrom.user_type || '';
      this.userFrom.status = this.userFrom.status || '';
      this.userFrom.belong_subject = this.userFrom.belong_subject || '';
      this.userFrom.sex = this.userFrom.sex || '';
      this.userFrom.is_promoter = this.userFrom.is_promoter || '';
      this.userFrom.country = this.userFrom.country || '';
      this.userFrom.pay_count = this.pay_count === 'all' ? '' : this.pay_count;
      this.userFrom.user_time_type = this.user_time_type === 'all' ? '' : this.user_time_type;
      this.userFrom.field_key = this.field_key === 'all' ? '' : this.field_key;
      this.userFrom.level = this.level === 'all' ? '' : this.level;
      this.userFrom.group_id = this.group_id === 'all' ? '' : this.group_id;
      let [th, filekey, data, fileName] = [[], [], [], ''];
      //   let fileName = "";
      let excelData = JSON.parse(JSON.stringify(this.userFrom));
      excelData.page = 1;
      for (let i = 0; i < excelData.page + 1; i++) {
        let lebData = await this.getExcelData(excelData);
        if (!fileName) fileName = lebData.filename;
        if (!filekey.length) {
          filekey = lebData.fileKey;
        }
        if (!th.length) th = lebData.header;
        if (lebData.export.length) {
          data = data.concat(lebData.export);
          excelData.page++;
        } else {
          this.$exportExcel(th, filekey, fileName, data);
          return;
        }
      }
    },
    getExcelData(excelData) {
      return new Promise((resolve, reject) => {
        exportUserList(excelData).then((res) => {
          resolve(res.data);
        });
      });
    },
    pageChange() {
      this.selectionList = [];
      this.getList();
    },

    // 搜索
    userSearchs() {
      this.userFrom.page = 1;
      this.getList();
    },
    // 重置
    reset(name) {
      this.userFrom = {
        user_type: this.userFrom.user_type,
        status: '',
        belong_subject: '',
        is_activity: '',
        sex: '',
        is_promoter: '',
        country: '',
        pay_count: '',
        user_time_type: '',
        user_time: '',
        nickname: '',
        field_key: '',
        level: '',
        group_id: '',
        label_id: '',
        page: 1, // 当前页
        limit: 20, // 每页显示条数
      };
      this.field_key = '';
      this.level = '';
      this.group_id = '';
      this.dataLabel = [];
      this.selectDataLabel = [];
      this.user_time_type = '';
      this.pay_count = '';
      this.timeVal = [];
      this.selectedIds = new Set();
      this.getList();
    },
    // 获取编辑表单数据
    getUserFrom(id) {
      getUserInfo(id)
        .then(async (res) => {
          this.modals = true;
          this.userData = res.data;
        })
        .catch((res) => {
          this.$message.error(res.msg);
        });
    },
    // 获取积分余额表单
    getOtherFrom(id) {
      this.$modalForm(editOtherApi(id)).then(() => this.getList(1));
    },
    // 修改状态
    onchangeIsShow(row) {
      let data = {
        id: row.uid,
        status: row.status,
      };
      isShowApi(data)
        .then(async (res) => {
          this.$message.success(res.msg);
        })
        .catch((res) => {
          this.$message.error(res.msg);
        });
    },
    // 点击发送优惠券
    onSend() {
      if (this.ids.length === 0) {
        this.$message.warning('请选择要发送优惠券的用户');
      } else {
        this.$refs.sends.modals = true;
        this.$refs.sends.getList();
      }
    },
    // 发送图文消息
    onSendPic() {
      if (this.ids.length === 0) {
        this.$message.warning('请选择要发送图文消息的用户');
      } else {
        this.modal13 = true;
      }
    },
    // 编辑
    edit(row) {
      this.getUserFrom(row.uid);
    },
    // 修改成功
    submitFail() {
      // this.getList();
    },
    // 排序
    sortChanged(e, props, order) {
      this.userFrom[e.prop] = e.order;
      this.getList();
    },
    //全选和取消全选时触发
    handleSelectAll(selection) {
      let ids = [];
      selection.map((e) => {
        ids.push(e.uid);
      });
      this.selectedIds = ids;
      this.$nextTick(() => {
        //确保dom加载完毕
        this.setChecked();
      });
    },
    //  选中某一行
    handleSelectRow(selection, row) {
      let ids = [];
      selection.map((e) => {
        ids.push(e.uid);
      });
      this.selectedIds = ids;
      this.$nextTick(() => {
        //确保dom加载完毕
        this.setChecked();
      });
    },
    setChecked() {
      //将new Set()转化为数组
      this.ids = [...this.selectedIds];
      // 找到绑定的table的ref对应的dom，找到table的objData对象，objData保存的是当前页的数据
      let objData = this.$refs.table.objData;
      for (let index in objData) {
        if (this.selectedIds.has(objData[index].uid)) {
          objData[index]._isChecked = true;
        }
      }
    },
  },
};
</script>

<style scoped lang="scss">
::v-deep .el-tabs__item {
  height: 54px !important;
  line-height: 54px !important;
}
.picBox {
  display: inline-block;
  cursor: pointer;

  .upLoad {
    width: 58px;
    height: 58px;
    line-height: 58px;
    border: 1px dotted rgba(0, 0, 0, 0.1);
    border-radius: 4px;
    background: rgba(0, 0, 0, 0.02);
    font-size: 24px;
    font-weight: 500;
  }

  .pictrue {
    width: 60px;
    height: 60px;
    border: 1px dotted rgba(0, 0, 0, 0.1);
    margin-right: 10px;

    img {
      width: 100%;
      height: 100%;
    }
  }
}

.userFrom {
  ::v-deep .ivu-form-item-content {
    margin-left: 0px !important;
  }
}

.userAlert {
  margin-top: 20px;
}

.userI {
  color: var(--prev-color-primary);
  font-style: normal;
}

img {
  height: 36px;
  display: block;
}

.tabBox_img {
  width: 36px;
  height: 36px;
  border-radius: 4px;
  cursor: pointer;

  img {
    width: 100%;
    height: 100%;
  }
}

.tabBox_tit {
  width: 60%;
  font-size: 12px !important;
  margin: 0 2px 0 10px;
  letter-spacing: 1px;
  padding: 5px 0;
  box-sizing: border-box;
}

.modelBox {
  ::v-deep .ivu-modal-body {
    padding: 0 16px 16px 16px !important;
  }
}

.vipName {
  color: #dab176;
}

.listbox {
  ::v-deep .ivu-divider-horizontal {
    margin: 0 !important;
  }
}

.labelInput {
  width: 250px;
  border: 1px solid #dcdee2;
  padding: 0 15px;
  border-radius: 5px;
  min-height: 30px;
  cursor: pointer;
  font-size: 12px;
  .span {
    color: #c5c8ce;
  }

  .ivu-icon-ios-arrow-down {
    font-size: 14px;
    color: #808695;
  }
}

.demo-drawer-footer {
  width: 100%;
  position: absolute;
  bottom: 0;
  left: 0;
  border-top: 1px solid #e8e8e8;
  padding: 10px 16px;
  text-align: right;
  background: #fff;
}
.search-form {
  display: flex;
  justify-content: space-between;
  .search-form-box {
    display: flex;
    flex-wrap: wrap;
    flex: 1;
  }
}
.search-form-sub {
  display: flex;
}
</style>
